﻿// JavaScript Document
var buttontype = true;
function getweather(){
	var name = document.getElementById("search").value;
	if(name == ""){
		alert("不能输入空值哦~");
		return;
		}
	$("#hide").fadeOut(500);
	$.ajaxSetup({ cache: false });
	$.getJSON("http://wthrcdn.etouch.cn/weather_mini",
		{city:name},function(json){
			if( json.desc!="OK")
			{
				alert("城市名不正确哦~");
				window.location.href="showweather.html";
			}
				
			cName = json.data.city;
			nTem = json.data.wendu;
			Ganmao = json.data.ganmao;
			toAqi = json.data.aqi;
			//今天的基本信息
			
			toFengxiang = json.data.forecast[0].fengxiang;
			toFengli = json.data.forecast[0].fengli;
			toGaowen = json.data.forecast[0].high;
			toDiwen = json.data.forecast[0].low;
			toType = json.data.forecast[0].type;
			toDate = json.data.forecast[0].date;
			//今天的详细数据(1)
			
			secFengxiang = json.data.forecast[1].fengxiang;
			secFengli = json.data.forecast[1].fengli;
			secGaowen = json.data.forecast[1].high;
			secDiwen = json.data.forecast[1].low;
			secType = json.data.forecast[1].type;
			secDate = json.data.forecast[1].date;
			//明天的详细数据(2)
			
			thrFengxiang = json.data.forecast[2].fengxiang;
			thrFengli = json.data.forecast[2].fengli;
			thrGaowen = json.data.forecast[2].high;
			thrDiwen = json.data.forecast[2].low;
			thrType = json.data.forecast[2].type;
			thrDate = json.data.forecast[2].date;
			//后天的详细数据(3)
			
			fouFengxiang = json.data.forecast[3].fengxiang;
			fouFengli = json.data.forecast[3].fengli;
			fouGaowen = json.data.forecast[3].high;
			fouDiwen = json.data.forecast[3].low;
			fouType = json.data.forecast[3].type;
			fouDate = json.data.forecast[3].date;
			//大后天的详细数据(4)
			
			fifFengxiang = json.data.forecast[4].fengxiang;
			fifFengli = json.data.forecast[4].fengli;
			fifGaowen = json.data.forecast[4].high;
			fifDiwen = json.data.forecast[4].low;
			fifType = json.data.forecast[4].type;
			fifDate = json.data.forecast[4].date;
			//大大后天的详细数据(5)
			
			yesFengxiang = json.data.yesterday.fx;
			yesFengli = json.data.yesterday.fl;
			yesGaowen = json.data.yesterday.high;
			yesDiwen = json.data.yesterday.low;
			yesType = json.data.yesterday.type;
			yesDate = json.data.yesterday.date;
			//昨天的详细数据
			
			yesGaowen = yesGaowen.match(/\d+/g);
			yesDiwen = yesDiwen.match(/\d+/g);
			toGaowen = toGaowen.match(/\d+/g);
			toDiwen = toDiwen.match(/\d+/g);
			secGaowen = secGaowen.match(/\d+/g);
			secDiwen = secDiwen.match(/\d+/g);
			thrGaowen = thrGaowen.match(/\d+/g);
			thrDiwen = thrDiwen.match(/\d+/g);
			fouGaowen = fouGaowen.match(/\d+/g);
			fouDiwen = fouDiwen.match(/\d+/g);
			fifGaowen = fifGaowen.match(/\d+/g);
			fifDiwen = fifDiwen.match(/\d+/g);
			//alert(yesDate);
			
			yDate = String(yesDate);
			yGaowen = Number(yesGaowen);
			yType = String(yesType);
			yDiwen = Number(yesDiwen);
			ydate = document.getElementsByTagName("h2")[0];
			ygaowen = document.getElementsByTagName("h4")[0];
			ydiwen = document.getElementsByTagName("h4")[1];
			ydate.innerHTML = yDate;
			ygaowen.innerHTML = yGaowen;
			ydiwen.innerHTML = yDiwen;
			
			if(yType.indexOf("雨")>=0){
				var yTq = "<img src='src/img/rain.png'/>"
				}
			else if(yType.indexOf("晴")>=0){
				var yTq = "<img src='src/img/sunny.png'/>"
				}
			else if(yType.indexOf("云")>=0){
				var yTq = "<img src='src/img/cloud.png'/>"
				}
			else if(yType.indexOf("雪")>=0){
				var yTq = "<img src='src/img/snow.png'/>"
				}
			else if(yType.indexOf("雾")>=0){
				var yTq = "<img src='src/img/fog.png'/>"
				}
			else if(yType.indexOf("阴")>=0){
				var yTq = "<img src='src/img/yin.png'/>"
				}
				ytype = document.getElementsByTagName("h3")[1];
				ytype.innerHTML = yTq;
			//1
			
			tDate = String(toDate);
			tGaowen = Number(toGaowen);
			tDiwen = Number(toDiwen);
			todate = document.getElementsByTagName("h2")[1];
			togaowen = document.getElementsByTagName("h4")[2];
			todiwen = document.getElementsByTagName("h4")[3];
			todate.innerHTML = tDate;
			togaowen.innerHTML = tGaowen;
			todiwen.innerHTML = tDiwen;
			toType = String(toType);
			if(toType.indexOf("雨")>=0){
				var toTq = "<img src='src/img/rain.png'/>"
				}
			else if(toType.indexOf("晴")>=0){
				var toTq = "<img src='src/img/sunny.png'/>"
				}
			else if(toType.indexOf("云")>=0){
				var toTq = "<img src='src/img/cloud.png'/>"
				}
			else if(toType.indexOf("雪")>=0){
				var toTq = "<img src='src/img/snow.png'/>"
				}
			else if(toType.indexOf("雾")>=0){
				var toTq = "<img src='src/img/fog.png'/>"
				}
			else if(toType.indexOf("阴")>=0){
				var toTq = "<img src='src/img/yin.png'/>"
				}
				totype = document.getElementsByTagName("h3")[2];
				totype.innerHTML = toTq;
			//2
			
			sDate = String(secDate);
			sType = String(secType);
			sGaowen = Number(secGaowen);
			sDiwen = Number(secDiwen);
			secdate = document.getElementsByTagName("h2")[2];
			sectype = document.getElementsByTagName("h3")[3];
			secgaowen = document.getElementsByTagName("h4")[4];
			secdiwen = document.getElementsByTagName("h4")[5];
			secdate.innerHTML = sDate;
			sectype.innerHTML = sType;
			secgaowen.innerHTML = sGaowen;
			secdiwen.innerHTML = sDiwen;
			if(secType.indexOf("雨")>=0){
				var secTq = "<img src='src/img/rain.png'/>"
				}
			else if(secType.indexOf("晴")>=0){
				var secTq = "<img src='src/img/sunny.png'/>"
				}
			else if(secType.indexOf("云")>=0){
				var secTq = "<img src='src/img/cloud.png'/>"
				}
			else if(secType.indexOf("雪")>=0){
				var secTq = "<img src='src/img/snow.png'/>"
				}
			else if(secType.indexOf("雾")>=0){
				var secTq = "<img src='src/img/fog.png'/>"
				}
			else if(secType.indexOf("阴")>=0){
				var secTq = "<img src='src/img/yin.png'/>"
				}
				sectype = document.getElementsByTagName("h3")[3];
				sectype.innerHTML = secTq;
			
			//3
			
			thDate = String(thrDate);
			thType = String(thrType);
			thGaowen = Number(thrGaowen);
			thDiwen = Number(thrDiwen);
			thrdate = document.getElementsByTagName("h2")[3];
			thrgaowen = document.getElementsByTagName("h4")[6];
			thrdiwen = document.getElementsByTagName("h4")[7];
			thrdate.innerHTML = thDate;
			thrgaowen.innerHTML = thGaowen;
			thrdiwen.innerHTML = thDiwen;
			if(thType.indexOf("雨")>=0){
				var thTq = "<img src='src/img/rain.png'/>"
				}
			else if(thType.indexOf("晴")>=0){
				var thTq = "<img src='src/img/sunny.png'/>"
				}
			else if(thType.indexOf("云")>=0){
				var thTq = "<img src='src/img/cloud.png'/>"
				}
			else if(thType.indexOf("雪")>=0){
				var thTq = "<img src='src/img/snow.png'/>"
				}
			else if(thType.indexOf("雾")>=0){
				var thTq = "<img src='src/img/fog.png'/>"
				}
			else if(thType.indexOf("阴")>=0){
				var thTq = "<img src='src/img/yin.png'/>"
				}
				thrtype = document.getElementsByTagName("h3")[4];
				thrtype.innerHTML = thTq;
			//4
			
			foDate = String(fouDate);
			foType = String(fouType);
			foGaowen = Number(fouGaowen);
			foDiwen = Number(fouDiwen);
			fodate = document.getElementsByTagName("h2")[4];
			fogaowen = document.getElementsByTagName("h4")[8];
			fodiwen = document.getElementsByTagName("h4")[9];
			fodate.innerHTML = foDate;
			fogaowen.innerHTML = foGaowen;
			fodiwen.innerHTML = foDiwen;
			
			if(foType.indexOf("雨")>=0){
				var foTq = "<img src='src/img/rain.png'/>"
				}
			else if(foType.indexOf("晴")>=0){
				var foTq = "<img src='src/img/sunny.png'/>"
				}
			else if(foType.indexOf("云")>=0){
				var foTq = "<img src='src/img/cloud.png'/>"
				}
			else if(foType.indexOf("雪")>=0){
				var foTq = "<img src='src/img/snow.png'/>"
				}
			else if(foType.indexOf("雾")>=0){
				var foTq = "<img src='src/img/fog.png'/>"
				}
			else if(foType.indexOf("阴")>=0){
				var foTq = "<img src='src/img/yin.png'/>"
				}
				foTq = "<img src='src/img/sunny.png'/>"
				fotype = document.getElementsByTagName("h3")[5];
				fotype.innerHTML = foTq;
			//5
			
			fiDate = String(fifDate);
			fiType = String(fifType);
			fiGaowen = Number(fifGaowen);
			fiDiwen = Number(fifDiwen);
			fidate = document.getElementsByTagName("h2")[5];
			figaowen = document.getElementsByTagName("h4")[10];
			fidiwen = document.getElementsByTagName("h4")[11];
			fidate.innerHTML = fiDate;
			figaowen.innerHTML = fiGaowen;
			fidiwen.innerHTML = fiDiwen;
			//fitype = document.getElementsByTagName("h3")[6];
			//fitype.innerHTML = fiType;
			
			if(fiType.indexOf("雨")>=0){
				var fiTq = "<img src='src/img/rain.png'/>"
				}
			else if(fiType.indexOf("晴")>=0){
				var fiTq = "<img src='src/img/sunny.png'/>"
				}
			else if(fiType.indexOf("云")>=0){
				var fiTq = "<img src='src/img/cloud.png'/>"
				}
			else if(fiType.indexOf("雪")>=0){
				var fiTq = "<img src='src/img/snow.png'/>"
				}
			else if(fiType.indexOf("雾")>=0){
				var fiTq = "<img src='src/img/fog.png'/>"
				}
			else if(fiType.indexOf("阴")>=0){
				var fiTq = "<img src='src/img/yin.png'/>"
				}
				fitype = document.getElementsByTagName("h3")[6];
				fitype.innerHTML = fiTq;
				
			//6
			//xj771293606
			cName = String(cName);
			Ganmao = String(Ganmao);
			nTem = Number(nTem);
			toAqi = Number(toAqi);
			var myDate = new Date();
			now = myDate.getHours(); 
			
			greet = document.getElementById("greetings");
			var greetings;
			if(now<=9&&now>=5){
				greetings = "早上好！<br><br>又是新的一天了，今天也要好好加油哦~";
				}
			else if(now>9&&now<13){
				greetings = "上午好。<br><br>忙碌的工作开始了，别忘了照顾好自己~";
				}
			else if(now>=13&&now<=17){
				greetings = "下午好。<br><br>一天快要结束了，有什么新的收获嘛~";
				}
			else if(now>=18&&now<=23){
				greetings = "晚上好。<br><br>生活其实挺惬意的。记得早点休息哦~";
				}
			else if(now>=0&&now<5){
				greetings = "夜深了，小叶依然陪着你。";
				}
			greet.innerHTML = "<font size='4'>"+greetings+"</font>";
			Whead = document.getElementById("Wheadfont");
			reminds = document.getElementById("reminds");
			
			
			
			if(toAqi<=50){
				var aqishow = "<font size='6' color='#0099FF'>"+toAqi+"&nbsp"+"优"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#0099FF'>空气清新哦，出去玩啦~<font>";
			}
			else if(toAqi>50&&toAqi<=100){
				var aqishow = "<font size='6' color='#99D6FF'>"+toAqi+"&nbsp"+"良"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#99D6FF'>一般般啦~<br>空气质量可接受，但某些污染物可能对极少数异常敏感人群健康有较弱影响，建议极少数异常敏感人群应减少户外活动。</font>";
			}
			else if(toAqi>100&&toAqi<=150){
				var aqishow = "<font size='6' color='#92ED57'>"+toAqi+"&nbsp"+"轻度污染"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#92ED57'>空气不是太好。<br>易感人群症状有轻度加剧，健康人群出现刺激症状。建议儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼。</font>";
			}
			else if(toAqi>150&&toAqi<=200){
				var aqishow = "<font size='6' color='#F3B250'>"+toAqi+"&nbsp"+"中度污染"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#F3B250'>有点难受…。<br>易感人群症状有轻度加剧，健康人群出现刺激症状。建议儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼。</font>";
			}
			else if(toAqi>200&&toAqi<=300){
				var aqishow = "<font size='6' color='#FF4E22'>"+toAqi+"&nbsp"+"重度污染"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#FF4E22'>还是不要出门啦。<br>心脏病和肺病患者症状显著加剧，运动耐受力降低，健康人群普遍出现症状，建议儿童、老年人和心脏病、肺病患者应停留在室内，停止户外运动，一般人群减少户外运动。</font>";
			}
			else if(toAqi>300){
				var aqishow = "<font size='6' color='#CC0000'>"+toAqi+"&nbsp"+"严重污染"+"</font>";
				var aqireminds = Ganmao+"<br><font size='4' color='#CC0000'>心塞。。<br>心脏病和肺病患者症状显著加剧，运动耐受力降低，健康人群普遍出现症状，建议儿童、老年人和心脏病、肺病患者应停留在室内，停止户外运动，一般人群减少户外运动。</font>";
			}
			Whead.innerHTML = "<font size='7'>"+cName+"</font><br>"+"<font size='5'>"+tDate+"</font><br><br>"+"空气质量指数为&nbsp"+aqishow;
			reminds.innerHTML = aqireminds;
			setTimeout("chBg()",500);
			
			
			$.ajaxSetup({ cache: true }); 
			})
	}

	function ofocus(){
			   buttontype = false;
			   $("#buttonindex").animate({'top':'1000px'},500);
			   setTimeout('$("#buttonindex").hide()',500);
			   $("#color").animate({'backgroundColor':'#CCFFCC'},500);
			   $("#search").animate({'border-color':'#FFFFFF'},500);
			   $("#logo").animate({'top':'-400px'},700);
			   $("#buttonprototype").attr("src","src/img/buttonprotot.png");	   
			   $("#main").animate({"backgroundColor":"#FFCCCC"},500);
			   $("#search").attr("placeholder","");
			   $("#buttonprototype").show();
			   $("#buttonprototype").animate({'top':'500px'},500);
			   
       }
	   
	function oblur(){
		$("#color").animate({'backgroundColor':'#FFFF99'},500);
		$("#logo").animate({'top':'0px'},700);
		$("#search").animate({'border-color':'#CCFF99'},500);
		$("#buttonprototype").attr("src","src/img/buttongrey.png");
		//$("#buttonprototype").attr("src","src/img/buttonprotot.png");
		$("#search").attr("placeholder","在这里输入城市名");
		$("#main").animate({"backgroundColor":"#FFF"},500);
		$("#buttonindex").show();
		$("#buttonindex").animate({'top':'500px'},500);
		$("#butonprototype").animate({'top':'700px'},500);
		setTimeout('$("#buttonprototype").hide()',500);
		buttontype = true;
		
		}
	function getX(){
		getX = [yDate,tDate,sDate,thDate,foDate,fiDate];
		return getX;
		}
	function getdata(){
		data = [{
            name: '高温',
            data: [yGaowen, tGaowen, sGaowen, thGaowen, foGaowen, fiGaowen]
        }, {
            name: '低温',
            data: [yDiwen, tDiwen, sDiwen, thDiwen, foDiwen, fiDiwen]
        }]
		return data;
		}
	function chBg(){
		$("#chart").fadeIn(500);
		$("#color").hide(500);
		$("#main").fadeOut(300,function(){$("#main").fadeIn(200).css("background-image","url(src/img/6f2a265adf8caf24aa6fb64ddd6b020b.jpg)");});
		$(".window").fadeOut(300);
		$(".window").fadeIn(300);
		
		setTimeout("$('#Whead').show(2000)",2000);
		$("#weather").show(700);
		setTimeout("getchart()",750);
		$("#greetings").fadeIn(2000);
		setTimeout("$('#greetings').animate({'left':'-500px'},1500);",2500);
		$("#share").show(200);
		}
	function changeBc(){
		document.getElementById("buttonprototype").setAttribute("src","src/img/buttonweather.png");
	}
	function backBc(){
		document.getElementById("buttonprototype").setAttribute("src","src/img/buttonprotot.png");
	}
	function changebutton(){
		document.getElementById("buttonindex").setAttribute("src","src/img/buttonindex2.png");
		}
	function backbutton(){
		document.getElementById("buttonindex").setAttribute("src","src/img/buttonindex.png");
		}
	function showreminds(){
		$("#reminds").show(500);
		//$("#reminds").fadeIn(500);
		}
	function hidereminds(){
		$("#reminds").hide(500);
		//$("#reminds").fadeOut(500);
		}